using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace BuddhistSchools.DTO.Models.Mapping
{
    public class StudentMap : EntityTypeConfiguration<Student>
    {
        public StudentMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.Name)
                .HasMaxLength(75);

            this.Property(t => t.ReligiousName)
                .HasMaxLength(75);

            this.Property(t => t.PhoneNumber)
                .HasMaxLength(17);

            this.Property(t => t.Address)
                .HasMaxLength(200);

            this.Property(t => t.Note)
                .HasMaxLength(300);

            // Table & Column Mappings
            this.ToTable("Student");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.Name).HasColumnName("Name");
            this.Property(t => t.ReligiousName).HasColumnName("ReligiousName");
            this.Property(t => t.Sex).HasColumnName("Sex");
            this.Property(t => t.Birthday).HasColumnName("Birthday");
            this.Property(t => t.BuddhistBirthday).HasColumnName("BuddhistBirthday");
            this.Property(t => t.PhoneNumber).HasColumnName("PhoneNumber");
            this.Property(t => t.Address).HasColumnName("Address");
            this.Property(t => t.Note).HasColumnName("Note");
            this.Property(t => t.PagodaID).HasColumnName("PagodaID");
            this.Property(t => t.ProvinceID).HasColumnName("ProvinceID");
            this.Property(t => t.SchoolClassID).HasColumnName("SchoolClassID");

            // Relationships
            this.HasOptional(t => t.Pagoda)
                .WithMany(t => t.Students)
                .HasForeignKey(d => d.PagodaID);
            this.HasOptional(t => t.Province)
                .WithMany(t => t.Students)
                .HasForeignKey(d => d.ProvinceID);
            this.HasRequired(t => t.SchoolClass)
                .WithMany(t => t.Students)
                .HasForeignKey(d => d.SchoolClassID);

        }
    }
}
